/*\
 * Copyright 2012 Rob van de Werken
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
\*/

var selected="";

var navigationGoto = function(anchor) {
	window.location.hash = "#"+anchor;
}
var navigationLoad = function(anchor) {
	selected = anchor;
	$('#main').load(anchor);
}
var navigationReload = function() {
	if(document.location.hash==""){
		navigationLoad('TVgXML.php');
	}else{
		navigationLoad(document.location.hash.substring(1));
	}
}

$(function() {
	$.ajaxSetup({
		timeout: 5000,
		error: function(xhr, ajaxOptions, thrownError){
			$('#main').html('Error: '+thrownError);
		}
	});
	$('#navigation').ajaxStop(function() {
		$('#navigation ul li a.selected').removeClass('selected');
		$('#navigation ul li a[href="#'+selected+'"]').addClass('selected');
	});
	
	$(window).bind('hashchange', function(){
		navigationLoad(document.location.hash.substring(1));
	});

	//$('a').click(navigationClick);
	navigationReload();

	//refresh every minute
	setInterval(function(){navigationReload();},60000);
});

